package com.xb.controller;

import com.xb.entity.DictType;
import com.xb.service.IDictTypeService;
import com.xb.util.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * entityController
 * /api/dictType
 */
@RestController
@RequestMapping("/api/dictType")
public class DictTypeController {
    @Autowired
    private IDictTypeService dictTypeService;

    @GetMapping("/getDictType")
    public Result getDictType() {
        return dictTypeService.getDictType();
    }

    @RequestMapping("/page")
    @RequiresPermissions("system:dictType:page")
    public Object findPage(DictType obj, @RequestParam(value = "page", defaultValue = "1") Integer page,
                           @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        return dictTypeService.selectDictTypeList(obj, page, limit);
    }

    @PostMapping
    @RequiresPermissions("system:dictType:add")
    public Object add(@RequestBody DictType obj) {
        Result result = new Result();
        if (dictTypeService.insertDictType(obj) > 0) {
            result.setStatus(Result.RESPONSE_SUCCESS);
            result.setMessage("添加成功！");
        } else {
            result.setMessage("添加失败！");
        }
        return result;
    }

    /**
     * 修改
     */
    @PutMapping
    @RequiresPermissions("system:dictType:update")
    public Object update(@RequestBody DictType obj) {
        Result result = new Result();
        if (dictTypeService.updateDictType(obj) > 0) {
            result.setStatus(Result.RESPONSE_SUCCESS);
            result.setMessage("修改成功！");
        } else {
            result.setMessage("修改失败！");
        }
        return result;
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    @RequiresPermissions("system:dictType:del")
    public Object del(@PathVariable Integer id) {
        Result result = new Result();
        if (dictTypeService.deleteDictTypeById(id) > 0) {
            result.setStatus(Result.RESPONSE_SUCCESS);
            result.setMessage("删除成功！");
        } else {
            result.setMessage("删除失败！");
        }
        return result;
    }
}
